<template>
  <div>
    <!-- 头部面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/wlecome' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>商品管理</el-breadcrumb-item>
    <el-breadcrumb-item :to="{path:'/goods'}">商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card style="margin-top:10px">
        <el-row>
            <el-col :span="8">
                <el-input placeholder="请输入内容">
                    <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
            </el-col>
            <el-col :span="4">
                <el-button type="primary" style="margin-left:10px" @click="add_goods_onfun">添加商品</el-button>
            </el-col>
        </el-row>
        <!-- 用户列表 -->
        <el-table
        :data="goods_list"
        stripe
        border
        fit
        style="width: 100%; margin-top: 20px">
        <el-table-column type="index" label="#">
        </el-table-column>
        <el-table-column
            prop="goods_name"
            label="商品名称"
            width="900px">
        </el-table-column>
        <el-table-column
            prop="goods_price"
            label="商品价格(元)">
        </el-table-column>
        <el-table-column
            prop="goods_weight"
            label="商品重量">
        </el-table-column>
        <el-table-column
            prop="add_time"
            label="创建时间">
        </el-table-column>
        <el-table-column label="操作" width="120px">
            <template>
                <el-button size="mini" type="primary" icon="el-icon-edit"></el-button>
                <el-button size="mini" type="danger" icon="el-icon-delete"></el-button>
            </template>
        </el-table-column>
        </el-table>

        <!-- 列表分页 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="goods_req_data_info.pagenum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="goods_req_data_info.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
    </el-card>
  </div>
</template>

<script>
    export default {
        data () {
            return {
                goods_list:[],
                total:0,
                goods_req_data_info:{
                    query:'',
                    pagenum:1,
                    pagesize:10   
                }
            }
        },
        methods: {
        // 获取商品列表的函数
            async get_goods_lists() {
                const {data: res_data} = await this.$axios.get('goods', {
                    params:this.goods_req_data_info
                });
                if(res_data.meta.status != 200) return this.$Message.error('完犊子,没找到!');
                this.goods_list = res_data.data.goods;
                this.total = res_data.data.total;
                return this.$Message.success('搞定');  
            },
            handleSizeChange(new_size) {
                this.goods_req_data_info.pagesize = new_size;
                this.get_goods_lists();
            },
            handleCurrentChange(new_pagenum) {
                this.goods_req_data_info.pagenum = new_pagenum;
                this.get_goods_lists();
            },
            // 添加商品 方法
            add_goods_onfun() {
                this.$router.push('/goods/add');               
            }
        },
        mounted () {
            this.get_goods_lists();
        }
    }
</script>

<style>

</style>